/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package binh;

import we.dispatcher.CPacketWriter;
import we.dispatcher.IDisposable;
import we.session.CSession;

/**
 *
 * @author ADMIN
 */
public class CClient implements IDisposable
{

    private CSession Session;
    public CChannel Channel;
    public CTable Table;
    private int ClientIndex;
    private int ClientStage;
    public String Username;
    public int AccountId;
    public boolean IsViewer;
    public int Chair;
    public int ExpAdd;
    public int Exp;
    public double GoldAdd;
    public int WinAdd;
    public int Ranking;
    public int Level;
    public int NewLevel;
    public int LostAdd;
    public double GoldBonus;
    public double Gold;
    public boolean IsBot;
    int AvatarId;
    boolean IsChickenBet;
    String RealName;
    public double GoldChicken;

    public CClient(int ClientIndex)
    {
        this.ClientIndex = ClientIndex;
    }

    public boolean IsLogin()
    {
        return ClientStage != CCommon.CS_BEFORE_LOGIN;
    }

    public void Send(CPacketWriter packet)
    {
        Session.Send(packet);
    }

    public void SendDuplicate(CPacketWriter packet)
    {
        Session.Send(packet.buffer().duplicate());
    }

    public String GetIP()
    {
        return Session.GetIP();
    }

    public CTable GetTable()
    {
        return Table;
    }

    public CChannel GetChannel()
    {
        return Channel;
    }

    public void LeftTable()
    {
        if (GoldChicken > 0)
        {
            this.Gold += GoldChicken;
            this.GoldChicken = 0;
        }

        // Reset thông tin
        this.IsChickenBet = false;
        this.Table = null;
        this.ClientStage = CCommon.CS_LOBBY;
        this.Chair = -1;
    }

    @Override
    public void dispose()
    {
        Session = null;
        Table = null;
        Channel = null;
        Session = null;
        ClientStage = CCommon.CS_BEFORE_LOGIN;
    }

    public void LeftChannel()
    {
        Channel = null;
        Table = null;
    }

    public void Join(CSession Session)
    {
        this.Session = Session;
    }

    public boolean IsUsed()
    {
        return (Session != null);
    }

    public void SetChannel(CChannel Channel)
    {
        this.Channel = Channel;
    }

    public int GetClientIndex()
    {
        return ClientIndex;
    }

    public void JoinTable(CTable Table)
    {
        this.Table = Table;
        this.ClientStage = CCommon.CS_IN_GAME;
    }

    public CSession GetSession()
    {
        return Session;
    }

    public double GetGold()
    {
        return Gold;
    }

    public void setClientStage(int Stage)
    {
        this.ClientStage = Stage;
    }

    public boolean IsPlayer()
    {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public void AddGold(double GoldAdd, String caro)
    {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public void UpdateScore()
    {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public double GetAvaiGoldAdd(double GoldBet)
    {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public boolean IsInTable()
    {
        return Table != null;
    }

    void JoinChannel(CChannel Channel)
    {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    CUserGame GetUserGame(int GetAppID)
    {
        CUserGame result = new CUserGame();
        result.Level = 2;
        return result;
    }
}